<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>品牌管理</title>
</head>
<body>
<h1>品牌管理</h1>

<form method="post" action="${pageContext.request.contextPath}/BrandServlet">
    <input type="hidden" name="action" value="add">
    <table>
        <tr>
            <td>品牌名称:</td>
            <td><input type="text" name="brandName"></td>
        </tr>
        <tr>
            <td>公司名称:</td>
            <td><input type="text" name="companyName"></td>
        </tr>
        <tr>
            <td>排序:</td>
            <td><input type="number" name="ordered"></td>
        </tr>
        <tr>
            <td>描述:</td>
            <td><input type="text" name="description"></td>
        </tr>
        <tr>
            <td>状态:</td>
            <td><input type="number" name="status"></td>
        </tr>
        <tr>
            <td colspan="2"><input type="submit" value="添加"></td>
        </tr>
    </table>
</form>

<form method="post" action="${pageContext.request.contextPath}/BrandServlet">
    <input type="hidden" name="action" value="selectAll">
    <input type="submit" value="查询所有">
</form>

<c:if test="${not empty brands}">
    <table border="1">
        <tr>
            <th>ID</th>
            <th>品牌名称</th>
            <th>公司名称</th>
            <th>排序</th>
            <th>描述</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        <c:forEach var="brand" items="${brands}">
            <tr>
                <td>${brand.id}</td>
                <td>${brand.brandName}</td>
                <td>${brand.companyName}</td>
                <td>${brand.ordered}</td>
                <td>${brand.description}</td>
                <td>${brand.status}</td>
                <td>
                    <a href="${pageContext.request.contextPath}/BrandServlet?action=selectById&id=${brand.id}">查看</a>
                    <a href="${pageContext.request.contextPath}/BrandServlet?action=updateForm&id=${brand.id}">更新</a>
                    <a href="${pageContext.request.contextPath}/BrandServlet?action=delete&id=${brand.id}">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>
</c:if>

<c:if test="${not empty brand}">
    <h2>品牌详情</h2>
    <table>
        <tr>
            <td>ID:</td>
            <td>${brand.id}</td>
        </tr>
        <tr>
            <td>品牌名称:</td>
            <td>${brand.brandName}</td>
        </tr>
        <tr>
            <td>公司名称:</td>
            <td>${brand.companyName}</td>
        </tr>
        <tr>
            <td>排序:</td>
            <td>${brand.ordered}</td>
        </tr>
        <tr>
            <td>描述:</td>
            <td>${brand.description}</td>
        </tr>
        <tr>
            <td>状态:</td>
            <td>${brand.status}</td>
        </tr>
    </table>
</c:if>

<c:if test="${not empty updateBrand}">
    <h2>修改品牌信息</h2>
    <form method="post" action="${pageContext.request.contextPath}/BrandServlet">
        <input type="hidden" name="action" value="update">
        <input type="hidden" name="id" value="${updateBrand.id}">
        <table>
            <tr>
                <td>品牌名称:</td>
                <td><input type="text" name="brandName" value="${updateBrand.brandName}"></td>
            </tr>
            <tr>
                <td>公司名称:</td>
                <td><input type="text" name="companyName" value="${updateBrand.companyName}"></td>
            </tr>
            <tr>
                <td>排序:</td>
                <td><input type="number" name="ordered" value="${updateBrand.ordered}"></td>
            </tr>
            <tr>
                <td>描述:</td>
                <td><input type="text" name="description" value="${updateBrand.description}"></td>
            </tr>
            <tr>
                <td>状态:</td>
                <td><input type="number" name="status" value="${updateBrand.status}"></td>
            </tr>
            <tr>
                <td colspan="2"><input type="submit" value="保存修改"></td>
            </tr>
        </table>
    </form>
</c:if>
</body>
</html>
